import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import util from '@/common/util.js';

export default {
  name: 'myClass',
  components: {},
  data () {
    return {
      studentId: '',
      studentName: '',
      siteId: '',
      keyWords: '',
      isChangeClassShow: false,
      status: '',
      isChangeClass: 0,
      pageNo: 1,
      content: [],
      content: {}
    }
  },
  mounted () {
    var _this = this
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.studentName = window.sessionStorage.getItem('studentName')
    _this.isChangeClass = window.sessionStorage.getItem('isChangeClass')
    let beginTime = window.sessionStorage.getItem('beginTime')
    let endTime = window.sessionStorage.getItem('endTime')
    let nowTime = new Date().getTime()
    if (nowTime >= beginTime && nowTime <= endTime) {
      _this.isChangeClassShow = true
    }
    //alert( _this.studentName)
    if (_this.studentName == '-1') {
      let params = '?siteId=' + _this.siteId + '&studentId=' + _this.studentId;
      http.get(CONSTANT.STUDENTVIEW + params, {
        siteId: this.siteId,
        studentId: this.studentId
      }, (res) => {
        _this.studentName = res.name
    })
    }
    _this.goList()
  },
  methods: {
    goRefund(applyId) {
      this.$router.push({path: '/refund',query:{applyId:applyId}})
    },
    goList () {
      var _this = this
      http.get(CONSTANT.MYCLASSLIST + '?userId=' + _this.studentId + '&orgId=' + _this.siteId + '&keyWords=' + _this.keyWords + '&status=' + _this.status + '&pageNo=' + _this.pageNo, {
      }, (res) => {
        let content = []
        let data = res.data.rows
        let isStudBack = window.sessionStorage.getItem('isStudBack')
        for (var i = 0; i < data.length; i++) {
          let cell = {}
          cell.name = data[i].apply.iclass.name
          cell.totalFees = data[i].apply.iclass.totalFee
          cell.applyStatus = data[i].apply.status
          if (cell.applyStatus == 0) {
            cell.applyStatusName = '预约中'
          } else if (cell.applyStatus == 1) {
            cell.applyStatusName = '可缴费'
            cell.payable = true
          } else if (cell.applyStatus == 2) {
            cell.applyStatusName = '已代缴'
          } else if (cell.applyStatus == 3) {
            cell.applyStatusName = '已缴费'
          } else if (cell.applyStatus == 4) {
            cell.applyStatusName = '已退费'
          } else if (cell.applyStatus == 5) {
            cell.applyStatusName = '已失效'
          } else if (cell.applyStatus == 6) {
            cell.applyStatusName = '已撤销'
          }
          cell.applyId = data[i].apply.id
          cell.year = data[i].apply.year
          cell.term = data[i].apply.caption.term
          cell.id = data[i].apply.iclass.id
          cell.beginDate = util.dateFormat(data[i].apply.iclass.beginDate,false)
          cell.endDate = util.dateFormat(data[i].apply.iclass.endDate,false)
          cell.classTime = data[i].apply.iclass.classTime
          cell.area = data[i].apply.caption.area
          cell.applyLimit = data[i].apply.caption.gradeMin + '～'  + data[i].apply.caption.gradeMax
          cell.spelName = data[i].apply.specialty.name
          cell.reserveNo = data[i].apply.reserveNo
          cell.timeable = data[i].apply.iclass.schedule
          if (data[i].apply.iclass.ageMin != null && data[i].apply.iclass.ageMax != null) {
            cell.ageMin = util.dateFormat(data[i].apply.iclass.ageMin,false)
            cell.ageMax = util.dateFormat(data[i].apply.iclass.ageMax,false)
          } else {
            cell.ageMin = ''
            cell.ageMax = ''
          }
          if (isStudBack == '1' && cell.applyStatus == 3) {
            cell.isRefund = true
          }
          content.push(cell)
        }
        if (data.length > 0) {
          if (_this.pageNo == 1) {
            _this.content = content
          } else {
            _this.content = _this.content.concat(content)
          }
        } else {
          if (_this.pageNo > 1) {
            _this.pageNo--
          }
          alert('没有更多了!')
        }
      })
    },
    lookMore () {
      var _this = this
      _this.pageNo++
      _this.goList()
    },
    comeBack () {
      this.$router.push({path: '/mine'})
    },
    goPxClassList(applyId,classId) {
      this.$router.push({path: '/pxClass',query:{applyId: applyId,oldClassId: classId}})
    },
    applyUndo(applyId) {
      if(confirm("撤销只撤销报名记录，已缴费的不会退回，如已缴费请不要撤销！"))
      {
        let _this = this
        http.post('http://47.96.62.199/eduplatform/api/public/ic/iclass/cancelInBatch', {
          applyId: applyId,
          userId: _this.studentId
        }, (res) => {
          alert(res.msg)
        _this.goList()
      })
      }
    },
    goPayment (id,applyStatus,applyStatusName,reserveNo,totalFees,paySerial) {//@click="goPayment(contents.id,contents.applyStatus,contents.applyStatusName)"
      let _this = this
      if (applyStatus == '1') {
        let params = '?siteId=' + _this.siteId + '&id=' + id + '&studentId=' + _this.studentId;
        http.get('http://47.96.62.199/eduplatform/api/public/px/apply/getDetailByReserveNo' + '?orgId=' + this.siteId + '&reserveNo=' + reserveNo, {
        }, (res) => {
          this.content.name = res.data.class.bean.name
        this.content.area = res.data.class.caption.area
        this.content.year = res.data.class.caption.year
        this.content.term = res.data.class.caption.term
        this.content.spelName = res.data.class.caption.spelId
        this.content.degree = res.data.class.caption.degree
        this.content.classNo = res.data.class.bean.code
        var query = {paySerial:res.data.pay.paySerial,reserveNo:reserveNo,name:this.content.name,totalFees:res.data.class.feeTotal,area:this.content.area,classNo:this.content.classNo,frontStatusName:this.content.frontStatusName,year:this.content.year,term:this.content.term,spelName:this.content.spelName,degree:this.content.degree,studentName:this.studentName}
        this.$router.push({path: '/payment',query:query})
      })
      }
    }
  }
}
